package com.sz.jinzheng.controller;

import com.sz.jinzheng.model.BorrowerInfo;
import com.sz.jinzheng.model.Result;
import com.sz.jinzheng.service.BorrowerInfoService;
import com.sz.jinzheng.until.JwtUntil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
public class BorrowerInfoController {
    @Autowired
    private BorrowerInfoService borrowerInfoService;
    @Autowired
    private JwtUntil jwtUntil;

    /**
     * 申请成功 创建一条任务
     * @param borrowerInfo
     * @return
     */
    @RequestMapping("/addBorrowerInfo")
    public Result addBorrowerInfo(@RequestBody BorrowerInfo borrowerInfo){
        Integer uid = jwtUntil.getUid(borrowerInfo.getToken());
        borrowerInfo.setUserId(uid);
        log.info(borrowerInfo.toString());
        int i = borrowerInfoService.addBorrowerInfo(borrowerInfo);
        if (i>0){

            return new Result(200,"申请成功",null);
        }
        return new Result(400,"申请失败请稍后重试",null);
    }




}
